package com.base.controller;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.base.comm.CommContent;
import com.base.po.voip.Sotre;
import com.base.service.LogsService;
import com.base.service.SotreService;
import com.base.utils.IP;
import com.base.utils.Produce;

/**
 * 添加商圈店铺信息服务端
 * 
 * @author f
 *
 */
@Controller
@RequestMapping("/admin")
public class add_Sotre {

	@Autowired
	private LogsService logsService; // log日志
	@Autowired
	private SotreService sotreService; // 商圈信息

	// 添加商圈信息
	@RequestMapping(value = "/toAddSotre", method = RequestMethod.POST)
	public @ResponseBody int toAddSotre(HttpServletRequest request, Sotre sotre) throws Exception {
		String parentid = sotre.getParentid(); // 获取代理商ID
		if (parentid == null) return -1; // 未获取到代理商信息
		List<Sotre> solist = sotreService.selectBySotre(new Sotre(sotre.getUserid(), parentid), null, null); // 获取当前用户的店铺信息
		if (solist != null && solist.size() > 0) return -2; // 添加店铺 每个用户只能添加一个
		sotre.setId(Produce.getUUID()); // 设置参数 主键ID
		sotre.setCreatetime(Produce.getNowDate()); // 创建时间
		sotre.setStatus((byte) 1); // 审核状态
		sotre.setDatastatus((byte) 1); // 数据状态
		logsService.insert(CommContent.TYPE_CREATE, CommContent.LOGS_XIAOXI + "配置商圈信息",
				(String) request.getSession().getAttribute("userNick"), true, IP.getIpAddr(request));
		return sotreService.insertSelective(sotre); // 添加
	}
}
